<?php
namespace Application\Repository;
use Doctrine\ORM\EntityRepository;

class UserFacebookRepository extends AbstractRepository
{
    protected  $entity="Application\\Entity\\UserFacebook";
    
    public function getByUid($uid,$number = 30)
    {
        $dql = "SELECT c FROM $this->entity c WHERE c.uid=?1";

        return $this->getEntityManager()->createQuery($dql)
                             ->setParameter(1, $uid)
                             ->setMaxResults($number)
                             ->getResult();
    }
    
    public function getUniqueByUid($uid,$number = 1)
    {
        $dql = "SELECT c FROM $this->entity c WHERE c.uid=?1";

        $results = $this->getEntityManager()->createQuery($dql)
                             ->setParameter(1, $uid)
                             ->setMaxResults($number)
                             ->getResult();
        return ($results!=null&&count($results)>0)?$results[0]:null;
    }
    
    
    public function getByUsername($username,$number = 30)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE c.uid=?1";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $username)
    	->setMaxResults($number)
    	->getResult();
    }
    
    
    public function getByEmail($email,$number = 30)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE c.email=?1";
    
    	return $this->getEntityManager()->createQuery($dql)
    	->setParameter(1, $email)
    	->setMaxResults($number)
    	->getResult();
    }
                    
    public function getListUserFacebook($arrayUserFacebookId)
    {
    	$dql = "SELECT c FROM $this->entity c WHERE";
    	$count=0;
    	foreach ($arrayUserFacebookId as $userFacebookId)
    	{
    	    if($count!=0)
    	    {
    	        $dql.=" OR";
    	    }
    	    $count++;
    	    $dql.=" c.uid=?$count";
    	}
    	$result=$this->getEntityManager()->createQuery($dql);
    	$count=0;
    	foreach ($arrayUserFacebookId as $userFacebookId)
    	{
    		$count++;
    		$result->setParameter($count, $userFacebookId);
    	}
    	return $result->getResult();
    }
    
   
}